package com.zwf.mapper;

import com.zwf.entity.AddressBook;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Author zwf
 * @date 2024/2/10 19:58
 */
@Mapper
public interface AddressBookMapper {

    /**
     * 新增地址
     * @param addressBook
     */
    @Insert("insert into address_book ( user_id, consignee, sex, phone, province_code, province_name, city_code, city_name, district_code, district_name, detail, label, is_default) " +
            "values " +
            "(#{userId},#{consignee},#{sex},#{phone},#{provinceCode},#{provinceName},#{cityCode},#{cityName},#{districtCode},#{districtName},#{detail},#{label},#{isDefault})")
    void add(AddressBook addressBook);

    /**
     * 条件查询当前登录用户的地址信息
     * @return
     */
    List<AddressBook> list(AddressBook addressBook);

    /**
     * 更新地址簿
     * @param addressBook
     */
    void update(AddressBook addressBook);

    /**
     * 将当前所有用户改为非默认地址
     * @param addressBook
     */
    @Update("update address_book set is_default=#{isDefault} where user_id=#{userId}")
    void updateAllToNotDef(AddressBook addressBook);

    /**
     * 根据id删除地址
     * @param id
     */
    @Delete("delete from address_book where id=#{id}")
    void deleteById(Long id);
}
